package cn.itcast.shop.order.adminaction;

import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.itcast.shop.categorysecond.vo.CategorySecond;
import cn.itcast.shop.order.service.OrdersService;
import cn.itcast.shop.order.vo.OrderItem;
import cn.itcast.shop.order.vo.Orders;
import cn.itcast.shop.utils.PageBean;

/**
 * 后台订单管理的Action
 * @author zzc
 *
 */
public class AdminOrderAction extends ActionSupport implements ModelDriven<Orders> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2755463793990732679L;
	private Orders orders = new Orders();
	
	@Override
	public Orders getModel() {
		return orders;
	}
	
	private OrdersService ordersService;

	public void setOrdersService(OrdersService ordersService) {
		this.ordersService = ordersService;
	}
	
	private Integer page;
	
	public void setPage(Integer page) {
		this.page = page;
	}

	public String findAllByPage(){
		
		PageBean<Orders> pageBean = ordersService.findByPage(this.page);
		
		ActionContext.getContext().getValueStack().set("pageBean", pageBean);
		return "findAllByPage";
	}
	
	/**
	 * 根据订单ID查询订单项
	 * @return
	 */
	public String findOrderItem(){
		List<OrderItem> oiList= ordersService.findOrderItem(orders.getOid());
		ActionContext.getContext().getValueStack().set("oiList", oiList);
		return "findOrderItem";
	}
	
	/**
	 * 修改订单状态的方法
	 * @return
	 */
	public String updateState(){
	  	Orders order= ordersService.findByOid(orders.getOid());
		order.setState(3);
		ordersService.update(order);
		return "updateStateSuccess";
	}
	
}






















